package com.atguigu.tingshu.order.adapter.impl;

import com.atguigu.tingshu.common.rabbit.constant.MqConst;
import com.atguigu.tingshu.common.rabbit.service.RabbitService;
import com.atguigu.tingshu.order.adapter.PayWay;
import com.atguigu.tingshu.order.service.OrderInfoService;
import com.atguigu.tingshu.vo.order.OrderInfoVo;
import org.springframework.stereotype.Service;

/**
 * <a href="https://www.shallowrecall.top/">Recall`Blog</a></br>
 * <a href="https://github.com/ShallowRecall">GitHub</a>
 *
 * @author Recall
 * @createTime 2025/06/09 16:53
 **/
@Service
public class WxPayWayImpl implements PayWay {
    private final OrderInfoService orderInfoService;
    private final RabbitService rabbitService;

    public WxPayWayImpl(OrderInfoService orderInfoService, RabbitService rabbitService) {
        this.orderInfoService = orderInfoService;
        this.rabbitService = rabbitService;
    }

    @Override
    public boolean isSupport(String payWay) {
        return "1101".equals(payWay);
    }

    @Override
    public void dealPayWay(OrderInfoVo orderInfoVo, Long userId, String orderNo) {

        // 微信支付逻辑
        // 1.保存订单相关的信息
        orderInfoService.saveOrderInfo(orderInfoVo, userId, orderNo);

        // 2.延时(30min)关单  给rabbitmq的延时交换机发送一条消息

        // rabbitService.sendDealyMessage(MqConst.EXCHANGE_CANCEL_ORDER, MqConst.ROUTING_CANCEL_ORDER, orderNo,60); // 测试使用
        rabbitService.sendDealyMessage(MqConst.EXCHANGE_CANCEL_ORDER, MqConst.ROUTING_CANCEL_ORDER, orderNo,60*30); // 线上使用

    }
}
